from bisect import bisect, bisect_right
from collections import defaultdict
from typing import List


class Solution:
    def numMatchingSubseq(self, s: str, words: List[str]) -> int:
        dic = defaultdict(list)
        ans = len(words)
        print(ans)
        for num, key in enumerate(s):
            dic[key].append(num)
        for i in words:
            if len(i) > len(s):
                ans -= 1
                continue
            point = -1
            for j in i:
                c = bisect_right(dic[j], point)
                if c == len(dic[j]):
                    ans -= 1
                    break
                point = dic[j][c]

        return ans



# 方法二  多指针


if __name__ == '__main__':
    s = "abcde"
    words = ["a", "bb", "acd", "ace"]

    dd = ["a","a"]
    print("cc 的长度")
    print(len(dd))


    solution = Solution()
    print(solution.numMatchingSubseq(s, words))
